/*
 * TimeRTC.pde
 * example code illustrating Time library with Real Time Clock.
 * 
 */

#include <Time.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

//global Variable 
bool RTCInitialized = false; 

bool setupRTC()  {
  if(!RTCInitialized){
    setSyncProvider(RTC.get);   // the function to get the time from the RTC
    
    RTCInitialized = (timeStatus()!= timeSet);
  }  
  
  return RTCInitialized;  
}


String Timestamp(){
  setupRTC();
  
  // digital clock display of the time
  String tmp = String(hour())+":"+printDigits(minute())+":"+printDigits(second());
  tmp += " "+String(day())+"."+String(month())+"."+String(year()); 

  return tmp;
}

String printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  String tmp="";
  if(digits < 10)
   tmp="0";
  return tmp + String(digits);
}
